#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/07/10 19:24
# @Author : zengxiaolong
# @File    : json_to_yaml.py
import yaml
import json


# json文件内容转换成yaml格式
def json_to_yaml(jsonPath):
    with open(jsonPath, encoding="utf-8") as f:
        datas = json.load(f)  # 将文件的内容转换为字典形式
        yamlDatas = yaml.dump(datas, indent=5, sort_keys=False, allow_unicode=True)
        print(yamlDatas)

def json_to_yaml_(jsonPath):
    with open(jsonPath, encoding="utf-8") as f:
        datas = json.load(f)  # 将文件的内容转换为字典形式
        isinstance_id_list = list(map(lambda x:x.get('gInstanceId'),datas.get('body').get('instances')))
        server_id_list = list(map(lambda x:x.get('gServerId'),datas.get('body').get('instances')))
        print(server_id_list)

if __name__ == "__main__":
    jsonPath = r"D:\pythonspace\api-auto\data\ceshi.json"
    json_to_yaml_(jsonPath)

